﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

namespace WMI.NET.CIM
{
    /// <summary>
    /// The CIM_NumericSensor class represents a numeric sensor that returns numeric readings and optionally supports thresholds settings.
    /// </summary>
    public class CIM_NumericSensor : CIM_Sensor
    {

        private Nullable<Int32> _Accuracy;
        private Nullable<int> _CurrentReading;
        private Nullable<Boolean> _IsLinear;
        private Nullable<Int32> _LowerThresholdCritical;
        private Nullable<Int32> _LowerThresholdFatal;
        private Nullable<Int32> _LowerThresholdNonCritical;
        private Nullable<Int32> _MaxReadable;
        private Nullable<Int32> _MinReadable;
        private Nullable<Int32> _NominalReading;
        private Nullable<Int32> _NormalMax;
        private Nullable<Int32> _NormalMin;
        private Nullable<UInt32> _Resolution;
        private Nullable<Int32> _Tolerance;
        private Nullable<Int32> _UpperThresholdCritical;
        private Nullable<Int32> _UpperThresholdFatal;
        private Nullable<Int32> _UpperThresholdNonCritical;


        /// <summary>
        /// Accuracy of the sensor for the measured property. Its value is recorded as plus or minus hundredths of a percent. This property, and the Resolution and Tolerance properties, are used to calculate the actual value of the measured physical property. Accuracy can vary depending on whether the device is linear over its dynamic range.
        /// </summary>
        public Nullable<Int32> Accuracy { get { return _Accuracy; } }

        /// <summary>
        /// Current value indicated by the sensor.
        /// </summary>
        public Nullable<int> CurrentReading { get { return _CurrentReading; } }

        /// <summary>
        /// If TRUE, the sensor is linear over its dynamic range.
        /// </summary>
        public Nullable<Boolean> IsLinear { get { return _IsLinear; } }

        /// <summary>
        /// Threshold value that specifies the ranges (minimum and maximum values) for determining whether the sensor is operating under normal, non-critical, critical, or fatal conditions. If the CurrentReading property is between LowerThresholdCritical and LowerThresholdFatal, then the current state is critical.
        /// </summary>
        public Nullable<Int32> LowerThresholdCritical { get { return _LowerThresholdCritical; } }

        /// <summary>
        /// 
        /// Threshold value that specifies the ranges (minimum and maximum values) for determining whether the sensor is operating under normal, non-critical, critical, or fatal conditions. If the CurrentReading property is below LowerThresholdFatal, then the current state is fatal.
        /// </summary>
        public Nullable<Int32> LowerThresholdFatal { get { return _LowerThresholdFatal; } }

        /// <summary>
        /// Threshold value that specifies the ranges (minimum and maximum values) for determining whether the sensor is operating under normal, non-critical, critical, or fatal conditions. If the CurrentReading property is between LowerThresholdNonCritical and UpperThresholdNonCritical, then the sensor is reporting a normal value. If the CurrentReading property is between LowerThresholdNonCritical and LowerThresholdCritical, then the current state is non-critical.
        /// </summary>
        public Nullable<Int32> LowerThresholdNonCritical { get { return _LowerThresholdNonCritical; } }

        /// <summary>
        /// Largest value of the measured property that can be read by the numeric sensor.
        /// </summary>
        public Nullable<Int32> MaxReadable { get { return _MaxReadable; } }

        /// <summary>
        /// Smallest value of the measured property that can be read by the numeric sensor.
        /// </summary>
        public Nullable<Int32> MinReadable { get { return _MinReadable; } }

        /// <summary>
        /// Expected or "normal" value for the numeric sensor.
        /// </summary>
        public Nullable<Int32> NominalReading { get { return _NominalReading; } }

        /// <summary>
        /// Normal maximum range for the numeric sensor.
        /// </summary>
        public Nullable<Int32> NormalMax { get { return _NormalMax; } }

        /// <summary>
        /// Normal minimum range for the numeric sensor.
        /// </summary>
        public Nullable<Int32> NormalMin { get { return _NormalMin; } }

        /// <summary>
        /// Ability of the sensor to resolve differences in the measured property. This value may vary depending on whether the device is linear over its dynamic range.
        /// </summary>
        public Nullable<UInt32> Resolution { get { return _Resolution; } }

        /// <summary>
        /// Tolerance of the sensor for the measured property. This property, and the Resolution and Accuracy properties, are used to calculate the actual value of the measured physical property. Tolerance may vary depending on whether the device is linear over its dynamic range.
        /// </summary>
        public Nullable<Int32> Tolerance { get { return _Tolerance; } }

        /// <summary>
        /// Threshold value that specifies the ranges (minimum and maximum values) for determining whether the sensor is operating under normal, non-critical, critical, or fatal conditions. If the CurrentReading property is between UpperThresholdCritical and UpperThresholdFatal, then the current state is critical.
        /// </summary>
        public Nullable<Int32> UpperThresholdCritical { get { return _UpperThresholdCritical; } }

        /// <summary>
        /// Threshold value that specifies the ranges (minimum and maximum values) for determining whether the sensor is operating under normal, non-critical, critical, or fatal conditions. If the CurrentReading property is above UpperThresholdFatal, then the current state is fatal.
        /// </summary>
        public Nullable<Int32> UpperThresholdFatal { get { return _UpperThresholdFatal; } }

        /// <summary>
        /// Threshold value that specifies the ranges (minimum and maximum values) for determining whether the sensor is operating under normal, non-critical, critical, or fatal conditions. If the CurrentReading property is between LowerThresholdNonCritical and UpperThresholdNonCritical, then the sensor is reporting a normal value. If the CurrentReading property is between UpperThresholdNonCritical and UpperThresholdCritical, then the current state is non-critical.
        /// </summary>
        public Nullable<Int32> UpperThresholdNonCritical { get { return _UpperThresholdNonCritical; } }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public CIM_NumericSensor(ManagementBaseObject mbo)
            : base(mbo)
        {
            _Accuracy = mbo.GetIntValue("Accuracy");
            _CurrentReading = mbo.GetIntValue("CurrentReading");
            _IsLinear = mbo.GetBoolValue("IsLinear");
            _LowerThresholdCritical = mbo.GetIntValue("LowerThresholdCritical");
            _LowerThresholdFatal = mbo.GetIntValue("LowerThresholdFatal");
            _LowerThresholdNonCritical = mbo.GetIntValue("LowerThresholdNonCritical");
            _MaxReadable = mbo.GetIntValue("MaxReadable");
            _MinReadable = mbo.GetIntValue("MinReadable");
            _NominalReading = mbo.GetIntValue("NominalReading");
            _NormalMax = mbo.GetIntValue("NormalMax");
            _NormalMin = mbo.GetIntValue("NormalMin");
            _Resolution = mbo.GetUIntValue("Resolution");
            _Tolerance = mbo.GetIntValue("Tolerance");
            _UpperThresholdCritical = mbo.GetIntValue("UpperThresholdCritical");
            _UpperThresholdFatal = mbo.GetIntValue("UpperThresholdFatal");
            _UpperThresholdNonCritical = mbo.GetIntValue("UpperThresholdNonCritical");
        }

    }
}
